﻿// See https://aka.ms/new-console-template for more information
using Newtonsoft.Json;
using RS.Snail.JJJ.Wechat;
using System.Text;
using WeChatBotClient.Models;

Console.WriteLine("Hello, World!");
var wxId = "wxid_7aw1s4bb657s12";

var wechat = new Service();
bool v = wechat.Init(
    new List<string> { wxId },
    msg => Console.Write(msg),
    msg => 
    {
        Console.Write(msg);
        return Task.CompletedTask;
    },
   (msg, isEnable) =>
   {
       Console.Write(msg);
       return Task.CompletedTask;
   });
wechat.StartReceive();

//var msgSend = wechat.MsgSendText(wxId, "18948845571@chatroom", "机器人消息");
//wechat.MsgSendText(wxId, "wxid_64050za6ck1p12", "机器人消息");
var userinfo = wechat.GetSelfInfo(wxId);
if (userinfo is null)
{
    Console.WriteLine("获取用户信息失败");
}
else
{
    Console.WriteLine(userinfo);
}

dynamic? friends = wechat.ContactGetList(wxId);
if (friends is null)
{
    Console.WriteLine("获取好友列表失败");
}
//else
//{
//    Console.WriteLine(friends);
//}
//var jsonStr = JsonConvert.SerializeObject(friends);

StringBuilder sb = new StringBuilder();
List<WxContact> wxContacts = JsonConvert.DeserializeObject<List<WxContact>>(friends);
//foreach (var contact in wxContacts)
//{
//    if (contact.wxType == 3 && contact.wxVerifyFlag == 0)
//    {
//        var code = wechat.ContactCheckStatus(wxId, contact.wxId);
//        if (177 != code)
//            sb.AppendLine($"删除好友 昵称:{contact.wxNickName} 备注:{contact.wxRemark} 好友状态码：{code}");
//    }
//}
Console.WriteLine(sb.ToString());


//var chatroomGetMember = wechat.ContaceChatGroupMemberNames(wxId, "18948845571@chatroom");
//if (chatroomGetMember is null)
//{
//    Console.WriteLine("获取群成员失败");
//}
//else
//{
//    Console.WriteLine(chatroomGetMember);
//}
//var delNumber = wechat.ContactCheckStatus(wxId, "alex_86");
//Console.WriteLine($"删除好友状态码:{delNumber}");
//var friendNumber = wechat.ContactCheckStatus(wxId, "wxid_64050za6ck1p12");
//Console.WriteLine($"好友状态码:{friendNumber}");
//wechat.MsgSendText(wxId, "wxid_64050za6ck1p12", "机器人消息");
Console.ReadLine();